<?php
function connexion(){
	$GLOBALS['con'] = mysql_connect("localhost","loco","1q2w3e4r");
	if (!$GLOBALS['con'])
	{
		die('Connexion impossible: ' . mysql_error());
	}
	mysql_select_db("pizzagamers", $GLOBALS['con']);
}

function deconnexion(){
	mysql_close($GLOBALS['con']);
	$GLOBALS['con'] = "";
}

function dbGet($class, $table, $where){
	$i=0;
	$objects = array();
	if(!empty($where)){
		$where = "WHERE ".$where;
	}
	connexion();
		$req=mysql_query("SELECT * FROM $table $where;");
		while($res = mysql_fetch_array($req)){
			$objects[$i] = new $class($res);
			$i++;
		}
	deconnexion();
	return $objects;
}

function dbAdd($table, $columns, $values){
	$id = -1;
	connexion();
		$req = mysql_query("INSERT INTO $table ($columns) VALUE ($values)");
		$id = mysql_insert_id();
	deconnexion();
	return $id;
}
?>